#! /usr/bin/perl -w

# --------------------------------------------------------------
# Filename : build_tree.pl
# Version  : "0.1"
# Date     : "2007-06-22 09:45:22"
# Author   : "Jiahuan Li <huanlf@gmail.com>"
# License  : "Licensed under the GPL v2"
# Copyright: "Copyright (C) 2007 by Jiahuan Li <huanlf@gmail.com>"
# 
# Description: to build a apt repositary tree
# --------------------------------------------------------------

use strict;

my $apt_root = '/var/www/apt/';
my @types    = qw/ dists /;
my @dists    = qw/ dapper edgy feisty/;
my @sessions = qw/ main /;
my @bin_arch = qw/ binary-i386 /;

unless ( -d $apt_root ) {
    mkdir $apt_root or system( "mkdir -p $apt_root" );
}
chdir $apt_root;

for my $t (@types) {
    mkdir $t unless -d $t;
    chdir $t;

    for my $d (@dists) {
        mkdir $d unless -d $d;
        chdir $d;

        for my $s (@sessions) {
            mkdir $s unless -d $s;
            chdir $s;

            if ($t =~ /pool/) { chdir '../'; next }
            for my $b (@bin_arch) {
                        mkdir $b unless -d $b;

                my $arch = $1 if $b =~ /(i386|amd64|ppc)/;
                (my $release_note =<<"                EOF") =~ s/^\s+//gm;
                    Archive: $d
                    Component: $s
                    Label: Prayaya China
                    Architecture: $arch
                EOF

                my $release_file = "$b/Release";
                open(FH, ">", $release_file )    or die "Can not write $release_file: $!";
                print FH $release_note; close FH or die "Can not close $release_file: $!";

            }
            chdir '../';
        }
        chdir '../';
    }
    chdir '../';
}

print "Done, now you can check $apt_root\n";

